package com.neuedu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.neuedu.pojo.*;
import com.neuedu.mapper.TNursingMapper;
import com.neuedu.pojo.dto.elder.ElderNurseDTO;
import com.neuedu.pojo.dto.nursing.NursingEldDTO;
import com.neuedu.service.ITElderService;
import com.neuedu.service.ITNursingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhangsan
 * @since 2024-06-17
 */
@Service
public class TNursingServiceImpl extends ServiceImpl<TNursingMapper, TNursing> implements ITNursingService {
    @Autowired
    TNursingMapper nursingMapper;
    @Autowired
    ITElderService elderService;
    @Override
    public Result<List<TNursing>> findWithEld(long eldId, String eldName, LocalDateTime nursingTimes) {
       /* List<NursingEldDTO> elderNurseDTOList = nursingMapper.selectList(null).stream().map(tNursing -> {
            NursingEldDTO nursingEldDTO = new NursingEldDTO();
            BeanUtils.copyProperties(tNursing, nursingEldDTO);
            TElder one = elderService.getOne(new LambdaQueryWrapper<TNurse>()
                    .eq(TNurse::getNurseId, tNursing.getNurseId()));
            if (one != null) {
                elderNurseDTO.setNurseName(one.getNurseName());
                elderNurseDTO.setNurseNumber(one.getNurseNumber());
                elderNurseDTO.setNurseId(one.getNurseId());
            }
            return elderNurseDTO;
        }).collect(Collectors.toList());*/
        return Result.success("查询成功");
    }

    @Override
    public Result<List<TNursing>> findAll() {
        List<TNursing> nursing=nursingMapper.selectList(null);
        return Result.success(nursing,"查询成功");
    }

    @Override
    public Result<List<TNursing>> findByEld(Long eldId, String nursingType) {
        LambdaQueryWrapper<TNursing> wapper = new LambdaQueryWrapper<>();
        wapper.eq(TNursing::getElderId,eldId)
                .eq(StringUtils.isNotBlank( nursingType),TNursing::getNursingType,nursingType)
                .orderByDesc(TNursing::getNursingTimes);
        List<TNursing> nursing=nursingMapper.selectList(wapper);
        return Result.success(nursing,"查询成功");
    }
}
